import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
// @ts-ignore
import json from '@rollup/plugin-json'
// @ts-ignore
import typescript from 'rollup-plugin-typescript'
// @ts-ignore
import postcssPresetEnv from 'postcss-preset-env'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
import path from "path";

const pathSrc = path.resolve(__dirname, "src");
console.log('pathSrc', pathSrc)

export default defineConfig({
    resolve: {
        alias: {
            "@": pathSrc,
        },
    },
    plugins: [
        vue(),
        monacoEditorPlugin({
            languageWorkers: ['css', 'html', 'json', 'typescript', 'editorWorkerService'],
        })
    ],
    // server: {
    //     host: false,
    // },
    // css: {
    //     preprocessorOptions: {
    //         less: {
    //             math: "always",
    //             globalVars: {
    //                 // mainColor: "red",
    //             }
    //         },
    //     },
    //     modules: {
    //         localsConvention: "camelCaseOnly",
    //         scopeBehaviour: 'local',
    //         generateScopedName: "[name]_[local]_[hash:5]",
    //         hashPrefix: 'hello',
    //     },
    //     devSourcemap: true,
    //     postcss: {
    //         plugins: [postcssPresetEnv()]
    //     }
    // },
    css: {
        devSourcemap: true,
    },
    build: {
        target: 'modules',
        outDir: "./dist",
        // minify: true,
        sourcemap: true,
        cssCodeSplit: false,
        // assetsInlineLimit: 40960,
        lib: {
            entry: 'src/index.ts',
            name: 'one-code-vue',
            formats: ['es'],
            fileName: "one-code-vue",
        },
        commonjsOptions: {},
        rollupOptions: {
            output: {
                name: "one-code-vue",
                exports: 'named',
                globals: {
                    vue: "Vue",
                },
            },
            external: [
                'vue',
                // 'lodash',
                'element-plus',
                // "codemirror",
                "ag-grid-vue3",
                'localforage',
                'json5',
                "vant",
                "axios",
                "echarts",
                "split.js",
                "pinia",
                "vue3-menus",
                "resize-observer-polyfill",
                "@element-plus/icons-vue",
                "@vicons/fa",
                "@vicons/utils",
                "axios"
            ],
            plugins: [
                typescript({
                    "include": [
                        "./src/**/*.ts",
                        "./src/**/*.js"
                    ],
                    "exclude": [
                        "./dist",
                        "./node_modules"
                    ]
                }),
                // postcss({
                //     extensions: ['.css'],
                //     extract: true,
                //     plugins: [
                //         simplevars(),
                //         nested(),
                //         cssnext({warnForDuplicates: false,}),
                //         // cssnano()
                //     ]
                // }),
                json(),
            ],
        },
    },
});